<template>
	<view class="conter">
		<!-- <header-box :title="title"></header-box> -->
		
		
		
		
		<view class="header" style="color: #000000;" @tap="goBack()">
			<view class="arrow">
			</view>
			<view class="title">
				{{title}}
			</view>
		</view>
		
		
		
		
		
		
		
		<view class="text-tab">
			<view class="box">
				<view class="marige-bor" v-for="(item, index) in textList" :key="index">
					<view class="diso-flex">
						<view class="">
							{{item.name}}
						</view>
						<view class="conter-image"  @tap="skip(item)">
							<u-radio-group v-model="value">
								<u-radio active-color="#AFB3F1" :name="item.id" ></u-radio>
							</u-radio-group>
						</view>
					</view>
				</view>
			</view>
		</view>


		<view class="add" @click="popupShow = true">
			<image src="../../static/index/add.png" mode=""></image>
		</view>

		<view class="flex-box total">
			<view class="">
				合计：
			</view>
			<view class="">
				{{total}} 个
			</view>
		</view>


		<!-- 底部弹层 -->
		<!-- <u-popup v-model="redactShow" mode="bottom" width="100%" height="200rpx" border-radius="40">
			<view class="padd-text" v-for="(item, index) in list" :key="index" @click="elect(item, index)">
				<text :class="[index == tabText ? 'color-text' : 'none-color']">{{item.name}}</text>
			</view>
		</u-popup> -->
		
		
		
		
		<u-popup v-model="popupShow" mode="center" width="70%" height="300rpx" border-radius="10">
			<view class="input-text">
				添加单位
			</view>
			<view class="input-val">
				<input type="text" v-model="inputName" style="background-color: #F0F0F0; text-align: center;border-radius: 10rpx;height: 100%;" placeholder="请输入单位" />
			</view>
			<view class="text-select">
				<view class="" @click="popupShow = false">
					取消
				</view>
				<view class="" @click="addClassName">
					确定
				</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	import headerBox from '../../components/header/header.vue'

	export default {
		components: {
			headerBox
		},
		data() {
			return {
				title: '选择单位',
				textList: [],
				addUrl: '',
				redactShow: false,
				list: [{
					name: '删除',
					show: true
				}, {
					name: '取消',
					show: false
				}],
				tabText: 0,
				popupShow: false,
				inputName: '',
				total: 0,
				id: '',
				value: '1',
				init: '',
				nitName: '',
			}
		},
		onLoad() {
			this.getClassList()
		},
		onShow() {

		},
		methods: {
			
			
			goBack() {
				let pages = getCurrentPages(); //获取所有页面栈实例列表
				   let nowPage = pages[pages.length - 1]; //当前页页面实例
				   let prevPage = pages[pages.length - 2]
				 prevPage.$vm.monad = this.value; //修改上一页data里面的searchVal参数值为1211
				 prevPage.$vm.init = this.value; //修改上一页data里面的searchVal参数值为1211
				 prevPage.$vm.monad = this.nitName; //修改上一页data里面的searchVal参数值为1211
				
				
				console.log(this.value)
				uni.navigateBack({
				    delta: 1
				})
			},
			
			// 获取分类列表
			async getClassList() {
				const { data: res} = await this.$u.post("api/jinxiao.Unit/index");
				this.textList = res
				this.value = res[0].id
				this.nitName = res[0].name
				this.total = res.length
			},
			
			// 确定添加单位
			async addClassName () {
				if(this.inputName == '') return this.$tools.msg('输入的内容不能为空')
				const res = await this.$u.post("api/jinxiao.Unit/add?name=" + this.inputName);
				this.popupShow = false
				this.inputName = ''
				this.$tools.msg(res.msg)
				this.getClassList()
				if(res.code != 1) {
					return this.$tools.msg(res.msg)
				}
				console.log(res)
			},
			
			
			skip(item) {
				// this.redactShow = true
				this.id = item.id
				this.init = item
				this.nitName = item.name
				console.log('跳转的路劲', item)
				// uni.navigateTo({
				// 	url: item.url
				// });
			},
			
			// 选择条件
			elect(item, index) {
				console.log(index)
				this.tabText = index
				this.redactShow = item.show
				if (index == 0) {
					
					// 调用删除事件
					this.removeClass(this.id)
				} else if (index == 1) {
					// 调用删除事件
				}
			},
			
			async removeClass (id) {
				const res = await this.$u.post("api/jinxiao.Unit/delete?id=" + id);
				if (res.code !== 1) return this.$tools.msg(res.msg)
				this.redactShow = false
				this.$tools.msg(res.msg)
				this.getClassList()
				
				console.log(res)
			}
		}
	}
</script>

<style lang="scss" scoped>
	.conter {
		width: 100%;
		height: 100%;
		position: relative;
		
		
		
		.header {
			width: 100%;
			height: 150rpx;
			line-height: 150rpx;
			display: flex;
			align-items: center;
			// padding-left: 10rpx;
			padding-top: 30rpx;
			font-size: 36rpx;
			font-family: PingFang SC;
			font-weight: 500;
			color: #FFFFFF;
			background: linear-gradient(to right, #656CE6, #9397FC);
			
			.arrow{
			  position: relative;
			  display: inline-block;
			}
			
			.arrow::before{
			  content: '';
			  width: 10px;
			  height: 10px;
			  border: 0px;
			  border-bottom: solid 2px #fff;
			  border-left: solid 2px #fff;
			  -ms-transform: rotate(45deg);
			  -webkit-transform: rotate(45deg);
			  transform: rotate(45deg);
			  position: absolute;
			  top: 50%;
			  left: 0;
			  margin-top: -4px;
			  margin-left: 28rpx;
			}
			
			.title {
				color: #fff;
				margin: 0 auto;
			}
		}
		
		
		

		image {
			width: 100%;
			height: 100%;
		}

		.text-tab {
			width: 100%;
			padding: 30rpx;
			padding-bottom: 0;


			.box {
				width: 98%;
				margin: 0 auto;
				background-color: #FFFFFF;
				border-radius: 10rpx;
			}

			.marige-bor {
				width: 90%;
				margin: 0 auto;
				color: #333333;
				display: flex;
				font-size: 28rpx;
				align-items: center;
				border-bottom: 1rpx solid #F0F0F0;
				justify-content: space-between;

				.diso-flex {
					width: 100%;
					height: 80rpx;
					display: flex;
					align-items: center;
					justify-content: space-between;
				}

				.conter-image {
					width: 22rpx;
					height: 36rpx;
					font-weight: 700;
					color: #999;
				}
			}

			.marige-bor:last-child {
				border-bottom: 0;
			}
		}

		// 加号
		.add {
			position: absolute;
			bottom: 200rpx;
			right: 40rpx;
			width: 120rpx;
			height: 120rpx;
			text-align: center;
			line-height: 100rpx;
			border-radius: 50%;
			font-size: 100rpx;
			color: #FFFFFF;
		}

		.total {
			width: 100%;
			position: absolute;
			bottom: 0;
			left: 0;
			height: 100rpx;
			padding: 0 60rpx 0 30rpx;
			background-color: #FFFFFF;
		}
		
	}
	
	.padd-text {
		width: 80%;
		height: 106rpx;
		line-height: 106rpx;
		text-align: center;
		font-size: 28rpx;
		color: #333;
		border-bottom: 1rpx solid #EEEEEE;
		margin: 0 auto;
	}
	
	.color-text {
		color: #7278EC;
	}
	
	.none-color {
		color: #000;
	}
	
	.input-text {
		width: 100%;
		height: 60rpx;
		line-height: 60rpx;
		text-align: center;
		margin-top: 20rpx;
	}
	
	.input-val {
		width: 80%;
		height: 78rpx;
		margin: 20rpx auto 30rpx;
	}
	
	.text-select {
		width: 90%;
		margin: 0 auto;
		border-top: 1rpx solid #F0F0F0;
		display: flex;
		// padding-top: 20rpx;
		justify-content: space-around;
		
		view {
			width: 50%;
			height: 80rpx;
			line-height: 80rpx;
			text-align: center;
			border-right: 1rpx solid #F0F0F0;
		}
		
		view:last-child {
			border-right: 0;
		}
	}
</style>
